package communication.definitions;

/**
 * This enumerated type represents the most primitive types which the robot and
 * client will communicate about.
 * <p>
 * Any time the list of devices is changed a new header file must be generated
 * by the <code>HeaderGenerator</code>.
 * 
 * @author Peter Kalauskas
 */
public enum DeviceType {
	ROBOT, CLIENT, ANALOG_DIGITAL_CONVERTER;

	/**
	 * Returns a byte for this DeviceType.
	 * 
	 * @return the byte corresponding to this DeviceType
	 */
	public byte byteValue() {
		return (byte) ordinal();
	}

	/**
	 * Returns a DeviceType for this byte.
	 * 
	 * @param b
	 *            the byte for which a DeviceType will be found
	 * @return the DeviceType corresponding to this byte
	 */
	public static DeviceType valueOf(byte b) {
		// Convert the byte to an unsigned int and return the DeviceType found
		// in the corresponding array of DeviceTypes
		return DeviceType.values()[b & 0xFF];
	}
}
